<template>
	<view class="container" :style="{minHeight:$height()}">
		<view class="header">
			<view class="search">
				<u-search placeholder="请输入手机号或姓名" :showAction="false" @search="search" v-model="keywords"></u-search>
			</view>
			<view class="person-count king-flex">
				<view class="item king-flex__column king-flex king-flex__center">
					<view class="sale">推广人数</view>
					<view class="sale-number">{{count}}</view>
				</view>
				<view class="item king-flex__column king-flex king-flex__center">
					<view class="sale">佣金总计</view>
					<view class="sale-number">{{commissionCount.totalMoney||0}}</view>
				</view>
			</view>
		</view>

		
		<view class="agent-list">
			<!-- <view class="item">
				<view class="name">代理人姓名</view>
				<view class="name">代理人电话</view>
			</view> -->

			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="name">{{item.realname}}</view>
				<view class="name">{{item.mobile}}</view>
			</view>

		</view>
		<!-- 加载更多 -->
		<u-loadmore v-if="list.length !== 0" :status="status" :load-text="loadText" />
		<image v-else src="@/static/image/empty.png" mode="widthFix" class="is-empty"></image>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				keywords: '',
				page: 1,
				limit: 30,
				videoSwitch: 0,
				more: false,
				// 页面数据初始化状态
				loadText: {
					loadmore: '轻轻上拉，加载更多',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
				commissionCount:{},
				list: [],
				
				count: 0,
			}
		},
		onLoad() {
			this.getUserRes()
			this.getRelationshipCount()
			this.getCommissionCount()
		},
		onShow() {
			this.getVideoSwitch()
		},
		//下拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.getUserRes()
		},
		//上拉加载
		onReachBottom() {
			if (this.page == 1) {
				return
			}
			if (this.more) {
				this.getUserRes()
			}
		},
		methods: {
			getVideoSwitch() {
				this.$axios.request(this.$api.getParamsConfig, "GET", {
					config: "VIDEO_SWITCH"
				}).then((val) => {
					this.videoSwitch = val.data.paramValue
				})
			},
			getCommissionCount() {
				this.$axios.request(this.$api.getCommissionCount, "GET").then((val) => {
					this.commissionCount = val.data
				})
			},
			getRelationshipCount() {
				this.$axios.request(this.$api.relationshipCount).then((val) => {
					this.count = val.data
				})
			},
			search(e) {
				this.page = 1
				this.getUserRes()
			},
			
			getUserRes() {
				this.$axios.request(this.$api.getRelationshipUser, "GET", {
					limit: this.limit,
					page: this.page,
					type: this.current,
					keywords: this.keywords,
					orderField: 'id',
					order: 'desc'
				}).then((val) => {
					uni.stopPullDownRefresh();
					this.list = this.page == 1 ? val.data.list : this.list.concat(val.data.list)
					if (Math.ceil(val.data.total / this.limit) > this.page) {
						this.more = true;
						this.page++
					} else {
						this.more = false;
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.agent-list {
		padding: 3%;

		.item {
			border-bottom: 1px solid #eaeaea;
			display: flex;
			line-height: 50rpx;
			font-size: 24rpx;
			text-align: center;

			.name {
				width: 50%;
				margin: auto;
			}

		}

		.item:last-child {
			border-bottom: none;
		}

	}

	.header {
		background-color: #2E6ADF;
		padding: 3%;
		height: 300rpx;

		.u-action-active {
			color: #FFFFFF !important;
		}

		.person-count {
			height: 140rpx;
			width: 100%;
			background-color: #FFFFFF;
			border-radius: 10px;
			margin: auto;
			margin-top: 40rpx;
		}

		.item {
			width: 50%;
			justify-content: center;
			height: 100%;

			.sale {
				font-size: 24rpx;
			}

			.sale-number {
				font-size: 26rpx;
				margin-top: 12rpx;
				font-weight: bold;
			}
		}

		.item:first-child {
			border-right: 1px solid #eaeaea;
		}

		.item:last-child {
			border: none;
		}
	}

	.footer {
		height: 100rpx;
		background-color: #FFFFFF;
		position: fixed;
		bottom: 0;
		width: 100%;
		box-shadow: 0px 19px 5px 19px #9E9E9E;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>